<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAppResourcesTable extends Migration
{
    private const TABLE = 'app_resources';

    public function up()
    {
        if (Schema::connection('gameCenter')->hasTable(self::TABLE)) {
            return;
        }
        Schema::connection('gameCenter')->create(self::TABLE, function (Blueprint $table) {
            $table->id();
            $table->unsignedInteger('appid')->default(0)->comment('应用ID');
            $table->unsignedInteger('source')->default(0)->comment("应用渠道");
            $table->unsignedTinyInteger('os')->default(0)->comment('系统');
            $table->string('version')->default('')->comment('版本');
            $table->string('min_version')->default('')->comment('最小版本号');
            $table->unsignedTinyInteger('is_debug')->default(0)->comment('测试资源');
            $table->string('url')->default('')->comment('资源地址');
            $table->string('bak_url')->default('')->comment('备份资源地址');
            $table->unsignedTinyInteger('status')->default(0)->comment('状态 0关闭 1开启');
            $table->timestamps();

            $table->index(['source', 'os']);
            $table->index('status');
        });
        DB::connection('gameCenter')->statement("ALTER TABLE `tb_".self::TABLE."` comment '应用资源'");
    }

    public function down()
    {
        Schema::connection('gameCenter')->dropIfExists(self::TABLE);
    }
}
